import { Config } from "../../src/config/Config";
import { DbConfig } from "../../src/config/DbConfig";
import { Logger } from "../../src/engine/utils/Logger";
import { MysqlClient } from "../../src/engine/utils/MySqlClient";
import { MysqlManager } from "../../src/engine/utils/MysqlManager";

export class LogScoreDao {

    public static DB_NAME: string = DbConfig.Db_Name.db_yxx;


    private static getDbName() {
        // if (Config.environment == Config.EnvironmentType.yueyouhui) {
        //     return DbConfig.Db_Name.db_yxx2
        // }
        // else if (Config.environment == Config.EnvironmentType.xj) {
        //     return DbConfig.Db_Name.db_yxx2
        // }
        // else if(Config.environment == Config.EnvironmentType.Jk){
        //     return DbConfig.Db_Name.db_jk
        // }
        // else if(Config.environment == Config.EnvironmentType.chaoyou){
        //     return DbConfig.Db_Name.db_chaoyouhui
        // }
        // else {
            return DbConfig.Db_Name.db_yxx
        // }
    }

    public static async get_log_score(startTime: number, endTime: number, uid: number, toId: number) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.getDbName());
        let sql: string = "select  * from  log_score  where dtime >= ? and dtime <= ?"
        if (uid != 0) {
            sql += " and uid=" + uid
        }
        if (toId != 0) {
            sql += " and tid=" + toId
        }
        let sqlParams = [startTime, endTime];
        let results = await client.queryPromise(sql, sqlParams);
        Logger.log("get_log_score=", sql, sqlParams, results)
        if (results && results.length > 0) {
            return results
        } else {
            return []
        }
    }
}